<template>
	<view class='cu-modal modal-bottom' :class='{show: show}'>
		<view class='modal'>
			<view class='head'>
				<text class='title'>设置标签</text>
				<text class='close cuIcon-close' @click='handleClose'></text>
			</view>
			<view class='form'>
				<view class='form-item'>
					<view class='label'>
						<image class='icon' mode='widthFix' src='/static/icon/user.png'></image>
						<text>客户名称:</text>
					</view>
					<view class='value'>{{item.name}}</view>
				</view>
				<view class='form-item'>
					<view class='label'>
						<image class='icon' mode='widthFix' src='https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/shoujihao.png'></image>
						<text>手机号:</text>
					</view>
					<view class='value'>{{item.telphone}}</view>
				</view>
			</view>
			<view class='tag-label'>标签</view>
			<view class='tags'>
				<view class='tag-item' v-if="item.id" :class='{active: selects.includes(item.id)}' v-for='item in tags'
					:key='item.id' @click='handleSelect(item)'>{{item.title}}</view>
			</view>
			<view class='submit' @click='handleSubmit'>确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				selects: [],
				tags: [],
				item:{},
				success:null,
			}
		},
		created() {
			
		},
		methods: {
			handleOpen(e) {
				this.item = e.item
				this.tags = JSON.parse(JSON.stringify(e.tags))
				this.selects = this.item.labels?this.item.labels.map(item=>item.id):[],
				this.success = e.success || null
				this.show = true;
				
			},
			handleClose() {
				this.show = false;
			},
			handleSubmit() {
				if(this.success){
					this.success(this.selects)
				}
				this.handleClose()
			},
			handleSelect(e) {
				if(this.selects.includes(e.id)) {
					let index = this.selects.findIndex(item => item == e.id);
					this.selects.splice(index,1)
				} else {
					this.selects.push(e.id)
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.modal {
		width: 100%;
		position: absolute;
		left: 0;
		bottom: 0;
		background: #FFFFFF;
		padding: 0 32rpx 76rpx 32rpx;
		text-align: left;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		
		.head {
			text-align: center;
			font-weight: 500;
			font-size: 30rpx;
			color: var(--h1Color);
			padding: 32rpx 0 64rpx 0;
			position: relative;
			
			.close {
				position: absolute;
				top:  32rpx;
				right: 0;
			}
		}
		
		.form {
			.form-item {
				margin-bottom: 40rpx;
				font-size: 30rpx;
				color: var(--h1Color);
				display: flex;
				align-items: center;
				
				&:last-child {
					margin: 0;
				}
				
				.label {
					width: 212rpx;
					
					.icon {
						width: 26rpx;
						height: 26rpx;
						margin-right: 12rpx;
					}
				}
			}
		}
		
		.tag-label {
			margin-top: 80rpx;
			font-weight: 600;
			font-size: 30rpx;
			color: var(--h1Color);
			line-height: 42rpx;
		}
		
		.tags {
			display: flex;
			flex-wrap: wrap;
			gap: 16rpx;
			margin-top: 24rpx;
			
			.tag-item {
				height: 72rpx;
				background: var(--tagBg);
				border-radius: 8rpx;
				padding: 0 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26rpx;
				color: var(--h1Color);
				
				&.active {
					background: var(--primaryBg);
					border: 2rpx solid #FFE359;
				}
			}
		}
		
		.submit {
			margin-top: 72rpx;
			width: 100%;
			height: 96rpx;
			background: #FFE359;
			border-radius: 48rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 600;
			font-size: 32rpx;
			color: #222222;
		}
	}
</style>